package wyh.controller.Patient;

import com.fasterxml.jackson.databind.ObjectMapper;
import wyh.pojo.Patient;
import wyh.pojo.User;
import wyh.service.PatientService;
import wyh.service.UserService;
import wyh.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//9666666666666666666 ok
@WebServlet("/Patient/getById")
public class GetByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int Id = Integer.parseInt(req.getParameter("Id"));
        System.out.println("访问/Patient/getById?id="+Id+".");

        PatientService service = new PatientService();
        Patient pojo = service.ServicegetById(Id);
        Result result= new Result(200,"查询成功",pojo);

        System.out.println("返回结果："+pojo+"。");
        System.out.println(pojo);

        ObjectMapper ojmapper = new ObjectMapper();
        String json = ojmapper.writeValueAsString(result);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
    }
}
